/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.compomics.xtandemparser.xmlreader.operations.parser;

import java.io.IOException;
import java.io.StringReader;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

/**
 *
 * @author Kenneth
 */
public class XmlParser {

    private static DefaultHandler handler;

    public static void parse(String xmlString, DefaultHandler handler) {
        XmlParser.handler = handler;
        try {
            SAXParserFactory factory = SAXParserFactory.newInstance();
            SAXParser saxParser = factory.newSAXParser();
            saxParser.parse(new InputSource(new StringReader(xmlString)), XmlParser.handler);
        } catch (ParserConfigurationException | SAXException | IOException e) {
            e.printStackTrace();
        }
    }

    public DefaultHandler getHandler() {
        return handler;
    }
}
